<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/28
 * Time: 14:24
 */

namespace app\modules\api\service;

use app\modules\api\models\AdminUser;
use app\lib\BaseFunction;
use yii\db\Query;

class LoginService
{
    /**
     * @param $name
     * @param $password
     * @return string|bool
     */
    public function verify($name, $password)
    {
        $model = new AdminUser();
        if ($info = $model->getUser($name, $password)) {
            //获取权限信息
            $db = new Query();
            $tmp = $db->select('*')->from('jingsourcing_adminrole')
                ->where(['id' => $info['role']])
                ->limit(1)
                ->one();
            $info['role'] = $tmp['id'];
            $info['new_rules'] = $tmp['new_rules'];
            return (new BaseFunction())->generateJwt($info);
        }
        return false;
    }
}